package com.ilikesoup.instant.compare;

import com.segi.uhomecp.park.access.util.inclusion.Inclusion;

import java.util.Collection;
import java.util.Objects;
import java.util.function.BiPredicate;

public class Comparers {

    public static <T> CompareResult<T, T> beanCompare(T left, T right, Inclusion<String> fieldNameInclusion) {
        return beanCompare(left, right, ComparePair.ofBeanEquals((Class<T>) left.getClass(), fieldNameInclusion));
    }

    public static <T> CompareResult<T, T> beanCompare(T left, T right, ComparePair<T, T, ?>... comparePairs) {
        return compare(left, right, Objects::equals, comparePairs);
    }

    public static <T> CompareResult<T, T> beanCompare(T left, T right, Collection<ComparePair<T, T, ?>> comparePairs) {
        return compare(left, right, Objects::equals, comparePairs.toArray(new ComparePair[comparePairs.size()]));
    }

    public static <L, R> CompareResult<L, R> compare(L left, R right, ComparePair<L, R, ?>... comparePairs) {
        return compare(left, right, Objects::equals, comparePairs);
    }

    public static <L, R> CompareResult<L, R> compare(L left, R right, BiPredicate<Object, Object> commonComparer, ComparePair<L, R, ?>... comparePairs) {
        Comparer<L, R> comparer = new Comparer<>(left, right, commonComparer);
        for (ComparePair<L, R, ?> comparePair : comparePairs) {
            comparer.process(comparePair);
        }
        return comparer.getResult();
    }

}
